package com.ruoyi.gas.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gas.domain.GetInRecord;
import com.ruoyi.gas.service.IGetInRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Controller
 *
 * @author h w
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/gas/get_in")
public class GetInRecordController extends BaseController
{
    @Autowired
    private IGetInRecordService getInRecordService;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('gas:get_in:list')")
    @GetMapping("/list")
    public TableDataInfo list(GetInRecord getInRecord)
    {
        startPage();
        List<GetInRecord> list = getInRecordService.selectGetInRecordList(getInRecord);
        return getDataTable(list);
    }

    /**
     * 查询列表
     */
//    @PreAuthorize("@ss.hasPermi('gas:get_in:recentList')")
    @GetMapping("/recentList")
    public List<GetInRecord> recentList(GetInRecord getInRecord)
    {
         return getInRecordService.selectGetInRecordRecentList(getInRecord);
    }

    /**
     * 导出列表
     */
    @PreAuthorize("@ss.hasPermi('gas:get_in:export')")
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GetInRecord getInRecord)
    {
        List<GetInRecord> list = getInRecordService.selectGetInRecordList(getInRecord);
        ExcelUtil<GetInRecord> util = new ExcelUtil<GetInRecord>(GetInRecord.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('gas:get_in:query')")
    @GetMapping(value = "/{getInId}")
    public AjaxResult getInfo(@PathVariable("getInId") Long getInId)
    {
        return success(getInRecordService.selectGetInRecordByGetInId(getInId));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('gas:get_in:add')")
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GetInRecord getInRecord)
    {
        getInRecord.setCreateBy(getLoginUser().getUsername());
        return toAjax(getInRecordService.insertGetInRecord(getInRecord));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('gas:get_in:edit')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GetInRecord getInRecord)
    {
        return toAjax(getInRecordService.updateGetInRecord(getInRecord));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('gas:get_in:remove')")
    @Log(title = "", businessType = BusinessType.DELETE)
	@DeleteMapping("/{getInIds}")
    public AjaxResult remove(@PathVariable Long[] getInIds)
    {
        return toAjax(getInRecordService.deleteGetInRecordByGetInIds(getInIds));
    }
}
